< previous page page_106 next page >

Page 106
Chapter Objectives
Learn the different data types available in Visual Basic
Learn to declare and name variables
Determine the scope and lifetime of variables
Understand variant data types
Sample Project File: \Chapter06\Variables.vbp
What Is a Variable?
A variable is a programming term for a value thats stored in your computer program. This value is created by your program and stored somewhere in the memory of your computer. An analogy might be your bank account number for your checking account. This number represents a certain amount of money in your account. You reference that amount of money with this account number. Thus, the account number is like a variable.
Data Types
Remember the game where you put the square peg into the square hole and a round peg into a round hole? You couldnt put the round peg into a square hole. This is similar to the concept of a data type. You can only put certain types of values into certain types of variables. It all depends on how you declare the variable.
Variables can store many different types of data. How you declare the variable determines the type of data you can store in it. There are 10 different data types supported by Visual Basic. The numeric data types all have a different range of numbers you can store in them. Make sure youre familiar with the limits of each of theseyou dont want a user typing in a number thats greater than the data type youre using, for example. This can be a common source of bugs in an application. Table 6.1 lists some of the data types you can store in a variable. This table is a list of just some of the data types available. Others youll learn about in later chapters.

 
< previous page page_106 next page >

If you like this book, buy it!